package gui;

import java.awt.Frame;
import java.awt.Button;
import java.awt.Label;
import java.awt.Dialog;
import java.awt.Panel;
import java.awt.Choice;
import java.awt.TextField;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import daten.Fachgebiet;
import daten.Professor;
import daten.ProfessorenContainer;

public class ProfessorErfassen extends Dialog implements ActionListener {
	private TextField tfVorname;
	private TextField tfNachname;
	private Choice chFachgebiet;

	public ProfessorErfassen(Frame owner) {
		super(owner, "Professor erfassen");

		this.setLayout(new BorderLayout());

		Panel p = new Panel();
		p.setLayout(new GridLayout(3, 2));

		Panel q = new Panel();
		q.setLayout(new GridLayout(1, 3));

		this.tfVorname = new TextField();
		this.tfNachname = new TextField();
		this.chFachgebiet = new Choice();

		this.chFachgebiet.add("");
		this.chFachgebiet.add("Theoretische Informatik");
		this.chFachgebiet.add("Software Engeneering");
		this.chFachgebiet.add("Multimedia");

		p.add(new Label("Vorname:"));
		p.add(tfVorname);
		p.add(new Label("Nachname:"));
		p.add(tfNachname);
		p.add(new Label("Fachrichtung:"));
		p.add(chFachgebiet);

		this.add(p, BorderLayout.CENTER);

		Button b = new Button("Erfassen");
		Button c = new Button("Abbrechen");

		b.addActionListener(this);
		c.addActionListener(this);

		q.add(b);
		q.add(c);

		this.add(q, BorderLayout.SOUTH);

		pack();
		setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("Abbrechen")) {
			this.dispose();
		}
		if (e.getActionCommand().equals("Erfassen")) {
			if (tfVorname.getText().equals("")
					|| tfNachname.getText().equals("")) {
				
			} else {
				if (chFachgebiet.getSelectedItem().equals("")) {
					Professor p = new Professor(tfVorname.getText(), tfNachname
							.getText());
					ProfessorenContainer.instance().addProfessor(p);
					this.dispose();

				} else {
					Professor p = new Professor(tfVorname.getText(), tfNachname
							.getText(), Fachgebiet.valueOf(chFachgebiet.getSelectedItem()));
					ProfessorenContainer.instance().addProfessor(p);
					this.dispose();
				}

			}
		}
	}
}
